import { computed } from 'vue'
const useSelectAndSumHook = (lists) => {
    /* 异步的问题,获取不到数据 */
    console.log(lists.value)
    /* 使用Vue的计算属性,可以获取数据 */
    const sum = computed(() => {
        let total = 0;
        lists.value.forEach((item) => {
            if (item.isSelected) {
                total += item.productCount * item.productPrice;
            }
        });
        return total;
    });
    const allSelected = computed({
        get: () => {
            return lists.value.every((item) => item.isSelected);
        },
        set: (val) => {
            lists.value.forEach((item) => {
                item.isSelected = val;
            });
        },
    });
    return { sum, allSelected };
}
export { useSelectAndSumHook };